﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shop.Core.Events
{
    public static class EventPublisherExtensions
    {
        public static T EntityRequired<T, Key>(this IEventPublisher eventPublisher, Key id, object[] paramters = null) where T : BaseEntity<Key>
        {
            EntityRequired<T, Key> required = new EntityRequired<T, Key>(id, paramters);
            eventPublisher.Publish(required);
            return required.Result;
        }

        public static void EntityInserted<T, Key>(this IEventPublisher eventPublisher, T entity) where T : BaseEntity<Key>
        {
            eventPublisher.Publish(new EntityInserted<T, Key>(entity));
        }

        public static void EntityUpdated<T, Key>(this IEventPublisher eventPublisher, T entity) where T : BaseEntity<Key>
        {
            eventPublisher.Publish(new EntityUpdated<T, Key>(entity));
        }

        public static void EntityDeleted<T, Key>(this IEventPublisher eventPublisher, T entity) where T : BaseEntity<Key>
        {
            eventPublisher.Publish(new EntityDeleted<T, Key>(entity));
        }
    }
}
